﻿// -----------------------------------------------------------------------
// <copyright file="ITodoListsContract.cs" company="Spardo, LLC">
// Copyright (c) 2011 SPardo, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a 
// copy of this software and associated documentation files (the "Software"), 
// to deal in the Software without restriction, including without limitation 
// the rights to use, copy, modify, merge, publish, distribute, sublicense, 
// and/or sell copies of the Software, and to permit persons to whom the 
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included 
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
// </copyright>
// -----------------------------------------------------------------------

namespace DotNet37Signals.Client.Basecamp.Contracts
{
    using System.ServiceModel;
    using System.ServiceModel.Web;
    using DotNet37Signals.Client.Basecamp.Models;
    using System;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    [ServiceContract]
    public interface ITodoListsContract : IBasecampContract
    {
        [OperationContract]
        [WebGet(UriTemplate = "/todo_lists.xml")]
        TodoLists GetList();

        [OperationContract]
        [WebGet(UriTemplate = "/todo_lists.xml?responsible_party={personId}")]
        TodoLists GetListByResponsiblePerson(string personId);

        [OperationContract]
        [WebGet(UriTemplate = "/todo_lists.xml?responsible_party={companyId}")]
        TodoLists GetListByResponsibleCompany(string companyId);

        [OperationContract]
        [WebGet(UriTemplate = "/projects/{projectId}/todo_lists.xml?filter={filter}")]
        TodoLists GetListInProject(string projectId, string filter);

        [OperationContract]
        [WebGet(UriTemplate = "/todo_lists/{todoListId}.xml")]
        TodoList Get(string todoListId);

        [OperationContract]
        [WebGet(UriTemplate = "/projects/{projectId}/todo_lists/new.xml")]
        TodoListNew New(string projectId);

        [OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "/projects/{projectId}/todo_lists.xml")]
        NewEntity Create(string projectId, TodoListNew list);

        [OperationContract]
        [WebGet(UriTemplate = "/todo_lists/{todoListId}/Edit.xml")]
        TodoListNew Edit(string todoListId);

        [OperationContract]
        [WebInvoke(Method = "PUT", UriTemplate = "/todo_lists/{todoListId}.xml")]
        void Update(string todoListId, TodoListNew list);

        [OperationContract]
        [WebInvoke(Method = "DELETE", UriTemplate = "/todo_lists/{todoListId}.xml")]
        void Delete(string todoListId);

        [OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "/projects/{projectId}/todo_lists/reorder.xml")]
        void Reorder(string projectId, TodoLists list);
    }

    public static class TodoListsContractExtensions
    {
        public static TodoLists GetListByResponsiblePerson(this ITodoListsContract contract, Int64 personId)
        {
            return contract.GetListByResponsiblePerson(personId.ToString());
        }

        public static TodoLists GetListByResponsibleCompany(this ITodoListsContract contract, Int64 companyId)
        {
            return contract.GetListByResponsibleCompany(string.Format("c{0}", companyId));
        }

        public static TodoLists GetListInProject(this ITodoListsContract contract, Int64 projectId, TodoListFilter filter)
        {
            return contract.GetListInProject(projectId.ToString(), filter.Value);
        }

        public static TodoList Get(this ITodoListsContract contract, Int64 todoListId)
        {
            return contract.Get(todoListId.ToString());
        }

        public static TodoListNew New(this ITodoListsContract contract, Int64 projectId)
        {
            return contract.New(projectId.ToString());
        }

        public static NewEntity Create(this ITodoListsContract contract, Int64 projectId, TodoListNew list)
        {
            return contract.Create(projectId.ToString(), list);
        }

        public static TodoListNew Edit(this ITodoListsContract contract, Int64 todoListId)
        {
            return contract.Edit(todoListId.ToString());
        }

        public static void Update(this ITodoListsContract contract, Int64 todoListId, TodoListNew list)
        {
            contract.Update(todoListId.ToString(), list);
        }

        public static void Delete(this ITodoListsContract contract, Int64 todoListId)
        {
            contract.Delete(todoListId.ToString());
        }

        public static void Reorder(this ITodoListsContract contract, Int64 projectId, TodoLists list)
        {
            contract.Reorder(projectId.ToString(), list);
        }
    }
}
